package com.happyscan138.makefun.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.happyscan138.makefun.BaseAdapter.my_release_question;
import com.happyscan138.makefun.R;
import com.happyscan138.makefun.View.RoundImageView;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Administrator on 2016/12/7.
 */

public class myReleaseQuestionAdapter extends BaseAdapter {
    Context mContext;

    public myReleaseQuestionAdapter(Context mContext, List<my_release_question> mdata) {
        this.mContext = mContext;
        this.mdata = mdata;
    }

    List<my_release_question> mdata;
    @Override
    public int getCount() {
        return mdata.size();
    }


    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder_myRelease_Question viewHolder;
        //判断converView是否为空
        if(view==null){
            viewHolder=new ViewHolder_myRelease_Question();
            view=View.inflate(mContext, R.layout.myselease_question_item,null);
            viewHolder.myrelease_question_head=(RoundImageView) view.findViewById(R.id.my_release_head);
           viewHolder.myrelease_question_name=(TextView) view.findViewById(R.id.my_release_name);
            viewHolder.myrelease_question_time=(TextView) view.findViewById(R.id.my_release_time);
            viewHolder.myrelease_question_text=(TextView) view.findViewById(R.id.my_release_text);
            viewHolder.myrelease_question_image=(ImageView) view.findViewById(R.id.my_release_image);
            viewHolder.myrelease_question_viewNum=(TextView) view.findViewById(R.id.my_release_viewNum);
            viewHolder.myrelease_question_answerNum=(TextView) view.findViewById(R.id.my_release_answerNum);
            viewHolder.myrelease_question_commentNum=(TextView) view.findViewById(R.id.my_release_commentNum);
            viewHolder.myrelease_question_goodNum=(TextView) view.findViewById(R.id.my_release_goodNum);

            //将viewHolder与converView绑定
            view.setTag(viewHolder);
        }else {
            //如果存在converView，取出保存在converView中的viewHolder
            viewHolder=(ViewHolder_myRelease_Question) view.getTag();
        }
        my_release_question bean=mdata.get(position);
        //通过viewHolder找到对应控件，避免每次通过findViewById找控件
        Picasso.with(mContext).load(bean.icon).into(viewHolder.myrelease_question_head);
        viewHolder.myrelease_question_name.setText(bean.name);
        viewHolder.myrelease_question_time.setText(bean.time);
        viewHolder.myrelease_question_text.setText(bean.text);
        Picasso.with(mContext).load((bean.image)).into(viewHolder.myrelease_question_image);
        viewHolder.myrelease_question_viewNum.setText(bean.viewNum+"");
        viewHolder.myrelease_question_answerNum.setText(bean.answerNum+"");
        viewHolder.myrelease_question_commentNum.setText(bean.commentNum+"");
        viewHolder.myrelease_question_goodNum.setText(bean.goodNum+"");
        return view;
    }
    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

}

class ViewHolder_myRelease_Question{
    public RoundImageView myrelease_question_head;
    public TextView myrelease_question_name;
    public TextView myrelease_question_time;
    public TextView myrelease_question_text;
    public ImageView myrelease_question_image;
    public TextView myrelease_question_viewNum;
    public TextView myrelease_question_answerNum;
    public TextView myrelease_question_commentNum;
    public TextView myrelease_question_goodNum;

}